package com.caocaog.market.data.transfer.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.data.transfer.entity.CcAgent;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liguang
 * @version 1.0.0
 * @Project jeecg-boot
 * @Package com.caocaog.market.data.transfer.mapper.xml
 * @ClassName CcAgentMapper.java
 * @createTime 2021年11月16日 09:40:00
 * @Description TODO
 */
@DS("sql-server-datasource")
public interface CcTestMapper {
    /**
     * 查询所有商家信息
     */
    // 已审核的商家信息
    //    @Select("select sid, login_name loginName,name,mobile,id_card_no idCardNo,ali_name aliName,ali_no aliNo," +
    //            "agent_sid agentSid,id_just_img zmImg,id_verso_img fmImg,hand_id_card handImg,audit_status as auditStatus from cc_shop_info    where audit_status=1")
    // 待审核的商家信息
        @Select("select sid, login_name loginName,name,mobile,id_card_no idCardNo,ali_name aliName,ali_no aliNo," +
                "agent_sid agentSid,id_just_img zmImg,id_verso_img fmImg,hand_id_card handImg,audit_status as auditStatus from cc_shop_info    where audit_status=0")
    List<Map<String,Object>> findAllShopInfo();
    /**
     * 查询所有门店信息
     *      只查询已审核的门店
     */
    // 已审核门店信息
//    @Select("select sid as merchantId,shop_name as shopName,ali_name aliName,ali_no aliNo,royalty,shop_logo as shopLogo,shop_license shopLicense," +
//            "send_order_type as sendOrderType,audit_status as auditStatus,member_sid as memberSid,longitude,latitude,is_working as isWork," +
//            "adcode,city_name as cityName,address,address_aoi as addressAoi,is_recommend isRecommend," +
//            "opening_hours1_start as tart,opening_hours1_end as nd,score,shop_type shopType," +
//            "max_dis as maxDis,free_send as freeSend,send_time_avg as sendTimeAvg,consume_avg as consumeAvg,sale_count as saleCount,pack_price as packPrice,send_need_money as sendNeedMoney,send_free_money as sendFreeMoney" +
//            " from cc_shop_info  where audit_status=1")
    // 待审核门店信息
    @Select("select sid as merchantId,shop_name as shopName,ali_name aliName,ali_no aliNo,royalty,shop_logo as shopLogo,shop_license shopLicense," +
            "send_order_type as sendOrderType,audit_status as auditStatus,member_sid as memberSid,longitude,latitude,is_working as isWork," +
            "adcode,city_name as cityName,address,address_aoi as addressAoi,is_recommend isRecommend," +
            "opening_hours1_start as tart,opening_hours1_end as nd,score,shop_type shopType," +
            "max_dis as maxDis,free_send as freeSend,send_time_avg as sendTimeAvg,consume_avg as consumeAvg,sale_count as saleCount,pack_price as packPrice,send_need_money as sendNeedMoney,send_free_money as sendFreeMoney" +
            ",audit_status as auditStatus from cc_shop_info  where audit_status=0")
    List<Map<String,Object>> findAllShops();

    /**
     * 查询cc_member中的login_name
     */
    @Select("select login_name from cc_member where sid=#{memberSid}")
    String findMemberLoginName(@Param("memberSid") int memberSid);

    /**
     * 查询所有未被删除的商品
     *      is_delete=0(表示该商品未被删除)
     *   前提是该商品的门店已经被拉到“曹操来了”新系统
     */
    @Select("select sid,shop_sid as shopSid,name,price,m_price as mPrice,pm_price as pmPrice,logo,short_name as shortName," +
            "code,short_desc as shortDesc,status as sxjzt,is_index as isIndex,is_hot as isHot,classify1,classify2,classify3," +
            "visti_count as vistiCount,sale_count as saleCount,sku_desc_json as skuJson,pack_price packPrice" +
            " from cc_goods where shop_sid = #{shopId} and is_delete=0")
    List<Map<String,Object>> allGoods(@Param("shopId") int shopId);


    /**
     * 查询商品分类
     */
    @Select("select sid,name,remark,is_show as isShow,sort   from  cc_shop_classify  where shop_sid=#{shopId}")
    List<Map<String,Object>> findGoodsClassify(@Param("shopId") int shopId);

    /**
     * 根据商品id查询商品规格
     */
    @Select("select sid,name,short_desc,price,pack_price packPrice,logo,stock,weight from cc_goods_sku where goods_sid=#{goodsId}")
    List<Map<String, Object>> findSkuByGoodsId(@Param("goodsId") int goodsId);


    /**
     * 查询订单表
     *      只查询未被删除的订单
     */
    @Select("select sid,agent_sid as agentSid,shop_sid shopSid,shop_mobile as shopMobile,shop_name  as shopName,order_no orderNo," +
            "order_type as orderType,order_status as orderStatus, order_source  as orderSource,pay_status payStatus,pay_way payWay," +
            "pay_serno paySerno,pay_time payTime,member_name  as memberName,member_mobile memberMobile,amount,discounts,pay_amount as payAmount," +
            "send_price sendPrice,pack_price packPrice,is_free_send isFreeSend,weight_price weightPrice,reward_money rewardMoney," +
            "order_dis orderDis,receipt_addr_sid as receiptAddrSid,receipt_name receiptName,receipt_mobile receiptMobile,receipt_addr receiptAddr," +
            "receipt_addr_aoi receiptAddrAoi,receipt_addr_house receiptAddrHouse,receipt_lon receiptLon,receipt_lat receiptLat," +
            "is_scheduling isScheduling,scheduling_time schedulingTime,receive_time receiveTime,reject_time rejectTime,reject_msg rejectMsg,create_date  createDate," +
            "cancel_time cancelTime,remark,send_type sendType,member_sid memberSid from cc_shop_order where is_delete=0 and shop_sid=#{shopId}")
    List<Map<String,Object>> findCcOrders(@Param("shopId") int shopId);

    /**
     * 查询订单中包含哪些商品
     */
    @Select("select sid,goods_sid goodsSid,goods_name goodsName,goods_logo goodsLogo,goods_price goodsPrice,goods_sku_sid goodsSkuSid,goods_sku_name goodsSkuName," +
            "goods_weight  goodsWeight,buy_count buyCount,total_money totalMoney,remark  from cc_shop_order_info  where order_sid=#{orderId}")
    List<Map<String,Object>> findCcOrderInfo(@Param("orderId") int orderId);
}
